<?php
if (!defined("EXPONENT")) exit("");
// 9/10/2009: Immanuel192 write this action add to cart
  global $db;
// remove all old cache
  $timeout=30*60; // 30 minutes
  $now=time();
  $db->delete("order_cache","add_date + {$timeout} < {$now}");
// get ticket string
 $ticket=exponent_sessions_getTicketString();
// get item id
 $item_id=0;
 // get anything the customer want to buy
 if (isset($_POST['disk'])) $disk=1;
 else $disk=0;
 if (isset($_POST['vocal'])) $vocal=1;
 else $vocal=0;
 if (isset($_POST['soundtrack'])) $soundtrack=1;
 else $soundtrack=0;
 if (isset($_POST['sheet'])) $sheet=1;
 else $sheet=0;
 if (!$disk && !$vocal && !$soundtrack && !$sheet) 
  exponent_flow_redirect();
 // next, check ID
 if (isset($_REQUEST['id'])) {
   $item_id=intval($_REQUEST['id']);
   // check if this is a true item id
   $item=$db->selectObject("album","id = {$item_id}");
   if ($item) {
      // check if it has stored in cart cache
      $cache=$db->selectObject("order_cache","ticket_string = '{$ticket}' AND item_id={$item_id}");
      if ($cache) {
        // modify current item
        if ($disk) $cache->main_disk++;
        if ($vocal) $cache->vocal++;
        if ($sheet) $cache->sheetbook++;
        if ($soundtrack) $cache->soundtrack++;
		$cache->add_date = $now;        
        $db->updateObject($cache,"order_cache","ticket_string = '{$ticket}' AND item_id = {$item_id}");
      } else {
        // add new item
        $cache=null;
        $cache->ticket_string=$ticket;
        $cache->item_id=$item_id;
		$cache->add_date = $now;
        if ($disk) $cache->main_disk=1;
        if ($vocal) $cache->vocal=1;
        if ($sheet) $cache->sheetbook=1;
        if ($soundtrack) $cache->soundtrack=1;		
        $db->insertObject($cache,"order_cache");
      }
      exponent_flow_redirect();
   } else
      echo SITE_403_HTML; 
 }
 else
  echo SITE_403_HTML;
?>
